import Vue from 'vue'
import VueRouter from 'vue-router'

const Index = () => import("../views/Index");
const Login = () => import("../views/login/Login");
const DashBoard = () => import("../views/main/DashBoard");
const Examination = () => import("../views/examination/Examination");
const Papers = () => import("../views/papers/Papers");
const Mine = () => import("../views/mine/Mine");

const Test = () => import("../views/examination/Test");
const aaa = () => import("../views/examination/aaa");
const bb = () => import("../views/examination/bb");

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    redirect: "/index"
  },
  {
    path: "/index",
    component: Index,
    children: [
      {
        path: "/",
        redirect: "login"
      },
      {
        path: "login",
        component: Login
      },
      {
        path: "dashboard",
        component: DashBoard,
        meta: {
          requireAuth: true
        },
        children: [
          {
            path: "/",
            redirect: "examination"
          },
          {
            path: "examination",
            component: Examination,
            meta: {
              requireAuth: true
            },
          },
          {
            path: "papers",
            component: Papers,
            meta: {
              requireAuth: true
            },
          },

          {
            path: "mine",
            component: Mine,
            meta: {
              requireAuth: true
            },
          },
          // {
          //   path: "test",
          //   component: Test,
          //   meta: {
          //     requireAuth: true
          //   },
          // }
        ]
      },
      {
        path: "/test",
        component: Test,
        meta: {
          requireAuth: true
        },
      }
    ]
  },

];

// 解决ElementUI导航栏中的vue-router在3.0版本以上重复点菜单报错问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
};

const router = new VueRouter({
  routes,
  mode: "history"
});

export default router
